package forward.Module.Modules.Render;

import forward.Client;
import forward.Module.Modules.Move.NoSlow;
import forward.Util.R3DUtil;
import forward.api.EventHandler;
import forward.api.Events.Render.EventRender2D;
import forward.Module.Module;
import forward.Module.ModuleType;
import forward.Module.Modules.Combat.Killaura;
import forward.api.Value.Mode;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.util.ResourceLocation;

import java.awt.*;

public class TargetHUD extends Module {
	public static Mode<Enum> mode = new Mode("Mode", "Mode", (Enum[]) TGHMode.values(), (Enum) TGHMode.Nov);
	public TargetHUD() {
		super("TargetHUD", new String[] { "targethud" }, ModuleType.Render);
		this.addValues(mode);
	}

	@EventHandler
	public void onRender(EventRender2D event) {
		if (mode.getValue()==TGHMode.Vanilla){
		ScaledResolution sr = new ScaledResolution(mc);
		final FontRenderer font2 = mc.fontRendererObj;
		if (Killaura.curTarget != null && Client.instance.getModuleManager().getModuleByClass(TargetHUD.class).isEnabled()
				& Client.instance.getModuleManager().getModuleByClass(Killaura.class).isEnabled()) {
			final String name = Killaura.curTarget.getName()+ " "+ Killaura.curTarget.hurtTime;
			font2.drawStringWithShadow(name, (float) (sr.getScaledWidth() / 2) - (font2.getStringWidth(name) / 2),
					(float) (sr.getScaledHeight() / 2 - 30), -1);
			Minecraft.getMinecraft().getTextureManager().bindTexture(new ResourceLocation("textures/gui/icons.png"));
			int i = 0;
			while ((float) i < Killaura.curTarget.getMaxHealth() / 2.0f) {
				Minecraft.getMinecraft().ingameGUI.drawTexturedModalRect((float) (sr.getScaledWidth() / 2)
						- Killaura.curTarget.getMaxHealth() / 2.0f * 10.0f / 2.0f + (float) (i * 10),
						(float) (sr.getScaledHeight() / 2 - 16), 16, 0, 9, 9);
				++i;
			}
			i = 0;
			while ((float) i < Killaura.curTarget.getHealth() / 2.0f) {
				Minecraft.getMinecraft().ingameGUI.drawTexturedModalRect((float) (sr.getScaledWidth() / 2)
						- Killaura.curTarget.getMaxHealth() / 2.0f * 10.0f / 2.0f + (float) (i * 10),
						(float) (sr.getScaledHeight() / 2 - 16), 52, 0, 9, 9);
				++i;
			}
		}
	} else if (mode.getValue()==TGHMode.Nov) {
			Edebug();
		}
	}
	private void Edebug() {
		final FontRenderer font2 = mc.fontRendererObj;
		ScaledResolution res = new ScaledResolution(this.mc);
		ScaledResolution sr2 = new ScaledResolution(this.mc);
		int y2 = 2;
		boolean count = false;
		Color color = new Color(1.0f, 0.75f, 0.0f, 0.45f);
		int x1 = 600;
		int y1 = 355;
		int x2 = 750;
		int y22 = sr2.getScaledHeight() - 50;
		int nametag = y1 + 12;
		double thickness = 0.014999999664723873;
		double xLeft = -20.0;
		double xRight = 20.0;
		double yUp = 27.0;
		double yDown = 130.0;
		double size = 10.0;
		int right = new ScaledResolution(this.mc).getScaledWidth() - new ScaledResolution(this.mc).getScaledWidth() / 2;
		int right2 = new ScaledResolution(this.mc).getScaledWidth() - new ScaledResolution(this.mc).getScaledWidth() / 2 + 30;
		int height = new ScaledResolution(this.mc).getScaledHeight() - 70;
		if ((Killaura.curTarget != null ? Killaura.curTarget :mc.pointedEntity ) != null || mc.pointedEntity != null) {
			Gui.drawRect((double)right, (double)(height - 50), (double)(right + 130), (double)(height - 90), (int)new Color(0, 0, 0, 130).getRGB());
			font2.drawString((Killaura.curTarget != null ? Killaura.curTarget :mc.pointedEntity ).getName(), right + 30, height - 87, 16777215);
			font2.drawString("HP:" + (int)((EntityLivingBase)(Killaura.curTarget != null ? Killaura.curTarget :mc.pointedEntity )).getHealth() + "/" + (int)((EntityLivingBase)(Killaura.curTarget != null ? Killaura.curTarget :mc.pointedEntity )).getMaxHealth() + " " + "Hurt:" + ((Killaura.curTarget != null ? Killaura.curTarget :mc.pointedEntity ).hurtResistantTime > 0), right + 30, height - 70, new Color(255, 255, 255).getRGB());
			font2.drawString("Coords: " + (int)(Killaura.curTarget != null ? Killaura.curTarget :mc.pointedEntity ).posX + " " + (int)(Killaura.curTarget != null ? Killaura.curTarget :mc.pointedEntity ).posY + " " + (int)(Killaura.curTarget != null ? Killaura.curTarget :mc.pointedEntity ).posZ, right + 30, height - 60, new Color(255, 255, 255).getRGB());
			R3DUtil.drawEntityOnScreen((int)(right + 14), (int)(height - 54), (int)15, (float)2.0f, (float)15.0f, (EntityLivingBase)((EntityLivingBase)(Killaura.curTarget != null ? Killaura.curTarget :mc.pointedEntity )));
			Gui.drawRainbowRectVertical((int)right2, (int)(height - 77), (int)((int)((float)right2 + 95.0f * (float)Math.min((int)right2, ((EntityLivingBase)((Killaura.curTarget != null ? Killaura.curTarget :mc.pointedEntity ))).getHealth() / ((EntityLivingBase)((Killaura.curTarget != null ? Killaura.curTarget :mc.pointedEntity ))).getMaxHealth()))), (int)(height - 73), (int)3, (float)1.0f);
			//Gui.drawRainbowRectVertical((int)right2, (int)(height - 77), (int)(right2 + 95.0f * Math.min(right2, (int)(((EntityLivingBase)Aura.blockTarget).getHealth() / ((int)((EntityLivingBase)Aura.blockTarget).getMaxHealth())))), (int)(height - 73),3, 1);
		}
	}
	enum TGHMode{
		Nov,
		Vanilla;
	}
}
